package com.www.dao.admin;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.www.domain.admin.Floor;
import com.www.domain.admin.Room;

/**
 * 房间dao
 */
@Repository
public interface RoomDao {
	/*
	 * 房间插入操作
	 */
	@Insert("insert into room(id,photo,sn,roomTypeId,floorId,status,remark) values(default,#{photo},#{sn},#{roomTypeId},#{floorId},#{status},#{remark})")
	public int add(Room room);
	
	/*
	 * 房间编辑操作
	 */
	@Update("update room set photo = #{photo}, sn = #{sn},roomTypeId = #{roomTypeId},floorId = #{floorId},status = #{status},remark = #{remark} where id = #{id}")
	public int edit(Room room);
	
	/*
	 * 删除房间信息
	 */
	@Delete("delete from room where id = ${value}")
	public int delete(Long id);
	
	/*
	 * 房间信息搜索查询
	 */
	@Select({"<script>" +
			"select * from room " +
			"where  1=1 " +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='floorId != null'> and floorId like '%${floorId}%'</if>" +
			"<if test='sn != null'> and sn like '%${sn}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='offset != null and pageSize != null'> limit #{offset},#{pageSize}</if>" +
		"</script>"})
	public List<Room> findList(Map<String, Object> queryMap);
	
	/*
	 * 获取所有房间信息
	 */
	@Select("select * from room")
	public List<Room> findAll();
	
	/*
	 * 模糊搜索总条数 
	 */
	@Select({"<script>" +
			"select count(*) from room " +
			"where  1=1 " +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='floorId != null'> and floorId like '%${floorId}%'</if>" +
			"<if test='sn != null'> and sn like '%${sn}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
		"</script>"})
	public Integer getTotal(Map<String, Object> queryMap);
	
	/*
	 * 获取单个房间信息
	 */
	@Select("select * from room where id = #{value}")
	public Room find(Long id);
	
	/*
	 * 根据房间编号获取单个房间信息
	 */
	@Select("select * from room where sn = #{value}")
	public Room findBySn(String sn);
	
	/*
	 * 楼层编号是否存在
	 */
	@Select("select * from floor where id = #{value}")
	public Floor findFloor(Long floor);
}
